package com.zzl.boot.bigevent.mapper;

import com.zzl.boot.bigevent.pojo.article;
import com.zzl.boot.bigevent.pojo.articleWarehouse;
import com.zzl.boot.bigevent.pojo.tag;
import com.zzl.boot.bigevent.pojo.warehouse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface warehouseMapper {
    //添加仓库
    @Select("insert into warehouse(warehouse_name,create_time,update_time,user_id) " +
            "values (#{warehouseName},now(),now(),#{userId})")
    void add(String warehouseName,Integer userId);
    //获取仓库列表
    @Select("select * from warehouse where user_id=#{userId}")
    List<warehouse> getList(Integer userId);
    //修改仓库
    @Select("update warehouse set warehouse_name=#{warehouseName} where id=#{id}")
    void update(warehouse warehouse);
    //删除仓库
    @Select("delete from warehouse where id=#{id}")
    void del(Integer id);

    @Select("insert into warehouse_article_ref(article_id,warehouse_id) " +
            "values(#{articleId},#{warehouseId}) " +
            "")
    void save(articleWarehouse articleWarehouse);
    @Select("select * from article where id in " +
            "(select article_id from warehouse_article_ref where warehouse_id=#{warehouseId})")
    List<article> listByWare(Integer warehouseId);
    //获取仓库文章数量
    @Select("select count(*) from warehouse_article_ref where warehouse_id=#{warehouseId}")
    Integer count(Integer warehouseId);
    //移出仓库文章
    @Select("delete from warehouse_article_ref where warehouse_id=#{wid} and article_id=#{aid}")
    void remove(Integer wid, Integer aid);

    @Select("select count(*) from warehouse_article_ref where " +
            "warehouse_id=#{warehouseId} and article_id=#{articleId}")
    int isExit(articleWarehouse articleWarehouse);

    @Select("insert into warehouse(warehouse_name,create_time,update_time,user_id) " +
            "values (#{默认仓库},now(),now(),(select id from user where user_name=#{username}))")
    void fristWarehouse(String username, String 默认仓库);
}
